package com.hisicom.scqxspxcjc.base.bean;

import com.hisicom.scqxspxcjc.base.enums.ResultEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * 封装返回信息
 */
@Data
public class Result implements Serializable {

    private static final long serialVersionUID = 5576237395711742681L;

    private boolean success = false;
    private String msg = "";
    private int code;
    private Object obj = null;

    /**
     * ajax失败
     *
     * @param resultEnum 失败的消息
     * @return {Object}
     */
    public static Result error(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        return result;
    }

    /**
     * ajax失败
     *
     * @param msg 失败的消息
     * @return {Object}
     */
    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        result.setObj(msg);
        return result;
    }

    /**
     * ajax成功
     *
     * @return {Object}
     */
    public static Result success() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        return result;
    }

    /**
     * ajax成功
     *
     * @param msg 消息
     * @return {Object}
     */
    public static Result success(String msg) {
        Result result = new Result();
        result.setSuccess(true);
        result.setMsg(msg);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(msg);
        return result;
    }

    /**
     * ajax成功
     *
     * @param obj 成功时的对象
     * @return {Object}
     */
    public static Result success(Object obj) {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setObj(obj);
        return result;
    }

    public boolean getSuccess() {
        return this.success;
    }
}